package Sort;


import java.util.Scanner;

/**
 * @author Liangyaoyun
 */
public class QuickSort {
    public static void quickSort(int[] nums) {
        quickSortInner(nums, 0, nums.length - 1);
    }

    public static void quickSortInner(int[] nums, int start, int end) {
        if (end - start <= 0) {
            return;
        }
        int i = start;
        int j = end;
        while (i < j) {
            //如果ij不相遇且nums[j]>=nums[i],j继续向左走
            while (i < j && nums[j] >= nums[i]) {
                j--;
            }
            // 如果找到比j大的数进行交换
            //j从右向左走，如果nums[i]>nums[j],将两数交换
            if (nums[i] > nums[j]) {
                int tmp = nums[j];
                nums[j] = nums[i];
                nums[i] = tmp;
            }
            //如果ij不相遇且nums[j]>=nums[i],i继续向右走
            while (i < j && nums[i] <= nums[j]) {
                i++;
            }
            //i从左向右走，如果nums[i]<nums[j],将两数交换
            if (i < j) {
                int tmp = nums[j];
                nums[j] = nums[i];
                nums[i] = tmp;
            }
        }
        int middle = i;

        //左半部分数组递归快排
        quickSortInner(nums, start, middle - 1);
        //右半部分数组递归快排
        quickSortInner(nums, middle + 1, end);

    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        int[] nums = new int[t];
        for (int i = 0; i < t; i++) {
            nums[i] = scanner.nextInt();
        }
        quickSort(nums);
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i]+" ");
        }
    }

}

